package com.example.workflow.message.event;

import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.client.spring.annotation.ExternalTaskSubscription;
import org.camunda.bpm.client.task.ExternalTaskHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 侯宁 on 2024/5/6
 */
@Slf4j
@Configuration
public class MessageEventExternalTaskService {

    @Bean
    @ExternalTaskSubscription(topicName = "wechatPay",
            processDefinitionKeyIn = {
                    "Process_message_event",
                    "Process_pool_lane"
            },
            lockDuration = 50_000)
    public ExternalTaskHandler wechatPay() {
        return (externalTask, externalTaskService) -> {
            log.info("微信支付");
            externalTaskService.complete(externalTask);
        };
    }

    @Bean
    @ExternalTaskSubscription(topicName = "alipay",
            processDefinitionKeyIn = {
                    "Process_message_event",
                    "Process_pool_lane"
            },
            lockDuration = 50_000)
    public ExternalTaskHandler alipay() {
        return (externalTask, externalTaskService) -> {
            log.info("阿里支付");
            externalTaskService.complete(externalTask);
        };
    }

    @Bean
    @ExternalTaskSubscription(topicName = "success_pay",
            processDefinitionKeyIn = {
                    "Process_message_event",
                    "Process_pool_lane"
            },
            lockDuration = 50_000)
    public ExternalTaskHandler successPay() {
        return (externalTask, externalTaskService) -> {
            log.info("支付成功");
            externalTaskService.complete(externalTask);
        };
    }
}
